package com.hoshiicloud.user.controller.rbac;

import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.rbac.entity.SysDepartmentUsers;
import com.hoshiicloud.user.service.rbac.SysDepartmentUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "部门关联用户控制器")
@RestController
@RequestMapping("/sys-department-users")
public class SysDepartmentUsersController {
    private final SysDepartmentUsersService sysDepartmentUsersServicel;
    public SysDepartmentUsersController(SysDepartmentUsersService sysDepartmentUsersServicel) {
        this.sysDepartmentUsersServicel = sysDepartmentUsersServicel;
    }



    @ApiOperation("新增部门关联用户")
    @PostMapping(value = "/add")
    public Response<Boolean> addSysDepartmentUsers(@RequestBody SysDepartmentUsers entity) {
        return Response.data(sysDepartmentUsersServicel.addSysDepartmentUsers(entity));
    }


    @ApiOperation("通过用户ID物理删除")
    @DeleteMapping(value = "/deletePhysicByUserId")
    public Response<Boolean> deletePhysicByUserId(@RequestBody Long userId) {
        if(userId == null){
            return Response.failed("用户ID不能为空");
        }
        return Response.data(sysDepartmentUsersServicel.deletePhysicByUserId(userId));
    }

    @ApiOperation("通过部门ID物理删除")
    @DeleteMapping(value = "/deletePhysicByDepartmentId")
    public Response<Boolean> deletePhysicByDepartmentId(@RequestBody Long departmentId) {
        if(departmentId == null){
            return Response.failed("部门ID不能为空");
        }
        return Response.data(sysDepartmentUsersServicel.deletePhysicByDepartmentId(departmentId));
    }


    @ApiOperation("通过部门查用户")
    @GetMapping(value = "/listUsersByDepartmentId/{departmentId}")
    public Response<List<Long>> listUsersByDepartmentId(@PathVariable("departmentId") Long departmentId) {
        return Response.data(sysDepartmentUsersServicel.listUsersByDepartmentId(departmentId));
    }

    @ApiOperation("通过用户查部门")
    @GetMapping(value = "/listDepartmentsByUserId/{userId}")
    public Response<List<Long>> listDepartmentsByUserId(@PathVariable("userId") Long userId) {
        return Response.data(sysDepartmentUsersServicel.listDepartmentsByUserId(userId));
    }
}
